package com.hatricks.is.base.stream.progressinputstream;

import cn.hutool.core.util.NumberUtil;

import java.math.BigDecimal;

/**
 * @packageName: com.glodon.qydata.archive.infrastructure.upload
 * @className: ProgressUtils
 * @author: yanyh yanyh@glodon.com
 * @date: 2024-04-17 15:34
 * @description: 计算进度工具类
 */
public class ProgressUtils {

    public static long calculateProgress(long currentProgressSize, long totalSize) {
        BigDecimal progressPercent = NumberUtil.mul(NumberUtil.div(String.valueOf(currentProgressSize), String.valueOf(totalSize)), 100);
        long progress = Long.parseLong(NumberUtil.decimalFormat("#", progressPercent));
        return progress == 0 ? 1L : progress;
    }

}
